﻿using System;
using System.Collections.Generic;
using System.Text;

namespace AMS.DataAccess.Filter
{
    /// <summary>
    /// 提供GUID类型的字段的过滤器。
    /// </summary>
    public class GuidFilterField : FilterField
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        public GuidFilterField(Guid value)
            :this(value, SqlOperations.Equals)
        {
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="value"></param>
        /// <param name="operation">Only Equals, IsNull or IsNotNull can be used.</param>
        public GuidFilterField(Guid value, SqlOperations operation)
        {
            if (operation != SqlOperations.Equals && operation != SqlOperations.IsNull && operation != SqlOperations.IsNotNull)
            {
                throw new ArgumentException("Only Equals, IsNull or IsNotNull can be used.");
            }

            StringOperations op = StringOperations.Equals;
            if (operation == SqlOperations.IsNotNull)
            {
                op = StringOperations.IsNotNull;
            }
            else if (operation == SqlOperations.IsNull)
            {
                op = StringOperations.IsNull;
            }

            field = new StringFilterField(value.ToString(), op);
        }

        private StringFilterField field;

        /// <summary>
        /// 返回形如" = '87523DD3-A8B0-4304-BD25-C4CACD009CE2'"的字符串
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return field.ToString();
        }
    }
}
